class_name AnimatedButtonProperty_ElasticScale
extends AnimatedButtonProperty

#region 属性
@export var squash_amount: Vector2 = Vector2(0.7,1.3)
@export var random_offset: Vector2 = Vector2(0,0)
@export_range(0,25) var speed: float = 10
@export_range(0,25) var cooldown: float = 0.2
var start_tick:int = -cooldown
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
func add_tween(btn:AnimatedButton,tween:Tween):
	if Time.get_ticks_msec() < start_tick + cooldown * 1000:
		return
	super(btn,tween)
	var init_scale = btn.get_or_add_init_property("scale",btn.scale)
	var target_scale = Vector2(randf_range(squash_amount.x-random_offset.x,squash_amount.x+random_offset.x),randf_range(squash_amount.y-random_offset.y,squash_amount.y+random_offset.y))
	var t:CallbackTweener = tween.tween_callback(func():
		while true:
			await btn.get_tree().create_timer(0.02).timeout
			btn.scale = lerp(btn.scale, target_scale, 0.02 * speed)
			if abs(btn.scale - target_scale) < Vector2(.01, .01):
					btn.scale = init_scale
					return
	)
	if delay > 0:
		t.set_delay(delay)
func add_resume_tween(btn:AnimatedButton,resume_tween:Tween):
	super(btn,resume_tween)
	var init_scale = btn.get_or_add_init_property("scale",btn.scale)
	var rt:CallbackTweener = resume_tween.tween_callback(func():
		btn.scale = init_scale
	)
	if resume_delay > 0:
		rt.set_delay(resume_delay)
#endregion
#region 公共方法
#endregion
#region 私有方法
#endregion
#region 生命周期函数
#endregion
